<template>
    <!--switchFullscreen-->
    <j-modal
            :title="title"
            :width="width"
            :visible="visible"
            fullscreen
            @ok="handleOk"
            :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
            @cancel="handleCancel"
            cancelText="关闭">
        <template slot="footer">
            <a-button @click="handleCancel">关闭</a-button>
            <a-button type="primary" @click="handleTest" v-if="testForm">测试</a-button>
            <a-button type="primary" @click="handleOk" v-if="editForm">确定</a-button>
        </template>

        <msi-exo-task-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" v-if="editForm"/>
        <msi-exo-task-test-form ref="testForm" :disabled="disableSubmit" v-if="testForm"/>
        <msi-exo-task-server-form ref="serverManageForm" :disabled="disableSubmit" v-if="serverManageForm"/>

    </j-modal>
</template>

<script>

    import MsiExoTaskForm from './MsiExoTaskForm'
    import MsiExoTaskServerForm from './MsiExoTaskServerForm'
    import MsiExoTaskTestForm from './MsiExoTaskTestForm'

    export default {
        name: 'MsiExoTaskModal',
        components: {
            MsiExoTaskForm, MsiExoTaskServerForm,MsiExoTaskTestForm
        },
        data() {
            return {
                title: '',
                editForm: true,
                testForm: false,
                serverManageForm: false,
                width: 1024,
                visible: false,
                disableSubmit: false
            }
        },
        methods: {
            add() {
                this.visible = true
                this.editForm = true
                this.testForm = false
                this.serverManageForm = false
                this.$nextTick(() => {
                    this.$refs.realForm.add()
                })
            },
            edit(record) {
                this.visible = true
                this.editForm = true
                this.testForm = false
                this.serverManageForm = false
                this.$nextTick(() => {
                    this.$refs.realForm.edit(record)
                })
            },
            test(record){
                this.visible = true
                this.editForm = false
                this.testForm = true
                this.serverManageForm = false
                this.$nextTick(() => {
                    this.$refs.testForm.edit(record)
                })
            },
            serverManage(record){
                this.visible = true
                this.editForm = false
                this.testForm = false
                this.serverManageForm = true
                this.$nextTick(() => {
                    this.$refs.serverManageForm.edit(record)
                })
            },
            close() {
                this.$emit('close')
                this.visible = false
            },
            handleOk() {
                this.$refs.realForm.submitForm()
            },
            submitCallback() {
                this.$emit('ok')
                this.visible = false
            },
            handleCancel() {
                this.close()
            },
            handleTest() {
                this.$refs.realForm.test()
            },

        }
    }
</script>
